<script setup>
import { useRouter, useRoute } from 'vue-router'
import { computed } from 'vue'

const router = useRouter()
const route = useRoute()

const tabs = [
  { name: 'home', path: '/', label: '首页', icon: '🏠' },
  { name: 'destination', path: '/destination', label: '目的地', icon: '🗺️' },
  { name: 'orders', path: '/orders', label: '订单', icon: '📋' },
  { name: 'ai', path: '/ai', label: 'AI智能推荐', icon: '🤖' },
  { name: 'profile', path: '/profile', label: '个人', icon: '👤' }
]

const activeTab = computed(() => {
  const currentPath = route.path
  return tabs.find(tab => currentPath === tab.path || currentPath.startsWith(tab.path + '/'))?.name || 'home'
})

const switchTab = (tab) => {
  if (route.path !== tab.path) {
    router.push(tab.path)
  }
}
</script>

<template>
  <nav class="tab-bar">
    <div
      v-for="tab in tabs"
      :key="tab.name"
      :class="['tab-item', { active: activeTab === tab.name }]"
      @click="switchTab(tab)"
    >
      <div class="tab-icon">{{ tab.icon }}</div>
      <span class="tab-label">{{ tab.label }}</span>
    </div>
  </nav>
</template>

<style scoped>
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-top: 1px solid #e8e8e8;
  display: flex;
  justify-content: space-around;
  padding: 8px 0;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  cursor: pointer;
  transition: all 0.2s;
  flex: 1;
}

.tab-item:active {
  transform: scale(0.95);
}

.tab-item.active {
  color: #1890ff;
}

.tab-icon {
  font-size: 22px;
  transition: transform 0.2s;
}

.tab-item.active .tab-icon {
  transform: scale(1.1);
}

.tab-label {
  font-size: 12px;
  font-weight: 500;
  color: #666;
  transition: color 0.2s;
}

.tab-item.active .tab-label {
  color: #1890ff;
  font-weight: 600;
}
</style>

